package com.atguigu.gmall.activity.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 秒杀下单的交换机和队列
 */
@Configuration
public class SeckillOrderAddRabbitConfig {

    /**
     * 交换机
     * @return
     */
    @Bean("seckillOrderAddExchange")
    public Exchange seckillOrderAddExchange(){
        return ExchangeBuilder.directExchange("seckill_order_exchange").build();
    }

    /**
     * 队列
     * @return
     */
    @Bean("seckillOrderAddQueue")
    public Queue seckillOrderAddQueue(){
        return QueueBuilder.durable("seckill_order_queue").build();
    }

    /**
     * 绑定
     * @param seckillOrderAddExchange
     * @param seckillOrderAddQueue
     * @return
     */
    @Bean
    public Binding binding(@Qualifier("seckillOrderAddExchange") Exchange seckillOrderAddExchange,
                           @Qualifier("seckillOrderAddQueue") Queue seckillOrderAddQueue){
        return BindingBuilder.bind(seckillOrderAddQueue).to(seckillOrderAddExchange).with("seckill.order").noargs();
    }
}
